//
//  AppointmentTodayCell.m
//  ICrEAM
//
//  Created by Cty on 2016/11/08.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "AppointmentTodayCell.h"

@implementation AppointmentTodayCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (UILabel *)time{
    if(!_time){
        
        _time = [[UILabel alloc]initWithFrame:CGRectMake(0, ActualHeight(10), ActualWidth(260), ActualHeight(34))];
        
        _time.textColor = [UIColor blackColor];
        _time.textAlignment = NSTextAlignmentCenter;
        _time.font = [UIFont systemFontOfSize:ActualWidth(18)];
        
        [self addSubview:_time];
        
        //横的分割线
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, ActualHeight(95)-1, ScreenWidth, 1)];
        view.backgroundColor = [UIColor whiteColor];
        
        [self addSubview:view];
        
    }
    return _time;

}
- (UILabel *)plateNum{
    if(!_plateNum){
        
        _plateNum = [[UILabel alloc]initWithFrame:CGRectMake(0, self.time.bottomEdge, ActualWidth(260), ActualHeight(34))];
        
        _plateNum.textColor = Color(0x666666);
        _plateNum.textAlignment = NSTextAlignmentCenter;
        _plateNum.font = [UIFont systemFontOfSize:ActualWidth(18)];
        
        [self addSubview:_plateNum];
        
    }
    return _plateNum;
}
- (UILabel *)status{
    if(!_status){
        
        _status = [[UILabel alloc]initWithFrame:CGRectMake(self.plateNum.rightEdge, 0, ActualWidth(150), ActualHeight(95))];
        
        _status.textColor = [UIColor blackColor];
        _status.textAlignment = NSTextAlignmentCenter;
        _status.font = [UIFont systemFontOfSize:ActualWidth(18)];
        
        [self addSubview:_status];
        _status.centerY = ActualHeight(95)/2.0;
        
        //分割线
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(self.plateNum.rightEdge, 0, 1, ActualHeight(95))];
        view.backgroundColor = [UIColor whiteColor];
        [self addSubview:view];
        
        
    }
    return _status;
    
}
- (UILabel *)customerName{
    if(!_customerName){
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.status.rightEdge+ActualWidth(20), ActualHeight(30), ActualWidth(40), ActualHeight(40))];
        imageView.image = [UIImage imageNamed:Appointment_Customer];
        imageView.centerY = ActualHeight(95)/2.0;
        
        _customerName = [[UILabel alloc]initWithFrame:CGRectMake(imageView.rightEdge+10, ActualHeight(10),ActualWidth(140), ActualHeight(34))];
        _customerName.font = [UIFont systemFontOfSize:ActualWidth(18)];
        
        _customerName.textAlignment = NSTextAlignmentLeft;
        
        _customerName.textColor = Color(0x000000);
        [self addSubview:imageView];
        [self addSubview: _customerName];
        //右侧分割线
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(self.status.rightEdge, 0, 1, ActualHeight(95))];
        view.backgroundColor = [UIColor whiteColor];
        [self addSubview:view];
        
        
    }
    return _customerName;
    
}
- (UILabel *)customerPhone{
    if(!_customerPhone){
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.status.rightEdge+ActualWidth(20), ActualHeight(30), ActualWidth(40), ActualHeight(40))];
        imageView.image = [UIImage imageNamed:Appointment_Customer];
        [_btnPreview addSubview:imageView];
        _customerPhone = [[UILabel alloc]initWithFrame:CGRectMake(imageView.rightEdge+10, self.customerName.bottomEdge,ActualWidth(140), ActualHeight(34))];
        _customerPhone.font = [UIFont systemFontOfSize:ActualWidth(18)];
        
        _customerPhone.textAlignment = NSTextAlignmentLeft;
        
        _customerPhone.textColor = Color(0x666666);
        
        [self addSubview: _customerPhone];
        
        
    }
    return _customerPhone;
    
}
- (UILabel *)assistantName{
    if(!_assistantName){
        
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.customerName.rightEdge+ActualWidth(20), ActualHeight(30), ActualWidth(40), ActualHeight(40))];
        imageView.image = [UIImage imageNamed:Appointment_Consultant];
        imageView.centerY = ActualHeight(95)/2.0;
        
        _assistantName = [[UILabel alloc]initWithFrame:CGRectMake(imageView.rightEdge+10, ActualHeight(10),ActualWidth(140), ActualHeight(34))];
        _assistantName.font = [UIFont systemFontOfSize:ActualWidth(18)];
        
        _assistantName.textAlignment = NSTextAlignmentLeft;
        
        _assistantName.textColor = Color(0x000000);
        
        [self addSubview: _assistantName];
        //右侧分割线
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(self.customerPhone.rightEdge, 0, 1, ActualHeight(95))];
        view.backgroundColor = [UIColor whiteColor];
        [self addSubview:imageView];
        [self addSubview:view];
    }
    return _assistantName;
    
}
- (UILabel *)assistantPhone{
    if(!_assistantPhone){
        
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.customerName.rightEdge+ActualWidth(20), ActualHeight(30), ActualWidth(40), ActualHeight(40))];
        imageView.image = [UIImage imageNamed:Appointment_Consultant];
        
        _assistantPhone = [[UILabel alloc]initWithFrame:CGRectMake(imageView.rightEdge+10, self.assistantName.bottomEdge,ActualWidth(140), ActualHeight(34))];
        _assistantPhone.font = [UIFont systemFontOfSize:ActualWidth(18)];
        
        _assistantPhone.textAlignment = NSTextAlignmentLeft;
        
        _assistantPhone.textColor = Color(0x666666);
        
        [self addSubview: _assistantPhone];
        
        
    }
    return _assistantPhone;
    
}
- (UIButton *)btnGetCar{
    if(!_btnGetCar){
        _btnGetCar = [[UIButton alloc]initWithFrame:CGRectMake(self.assistantPhone.rightEdge+ActualWidth(40), ActualHeight(25), ActualWidth(50), ActualHeight(55))];
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(ActualWidth(10), 0, ActualHeight(30), ActualWidth(30))];
        imageView.image = [UIImage imageNamed:Appointment_Car];
        [_btnGetCar addSubview:imageView];
        _btnGetCar.centerY = ActualHeight(95)/2.0;
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, imageView.bottomEdge+5, ActualWidth(50), ActualHeight(20))];
        [_btnGetCar addSubview:label];
        label.text = @"接车";
        label.textColor = TitleColor;
        label.textAlignment = NSTextAlignmentCenter;
        [_btnGetCar addSubview:label];
        
        [_btnGetCar addTarget:self action:@selector(didClickGetCarButton) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview: _btnGetCar];
        
        //右侧分割线
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(self.assistantPhone.rightEdge, 0, 1, ActualHeight(95))];
        view.backgroundColor = [UIColor whiteColor];
        [self addSubview:view];
        
        
    }
    return _btnGetCar;
    
}
- (UIButton *)btnPreview{
    if(!_btnPreview){
        _btnPreview = [[UIButton alloc]initWithFrame:CGRectMake(self.btnGetCar.rightEdge+ActualWidth(20), ActualHeight(25), ActualWidth(50), ActualHeight(55))];
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(ActualWidth(10), 0, ActualHeight(30), ActualWidth(30))];
        imageView.image = [UIImage imageNamed:Common_Preview];
        [_btnPreview addSubview:imageView];
        _btnPreview.centerY = ActualHeight(95)/2;
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, imageView.bottomEdge+5, ActualWidth(50), ActualHeight(20))];
        [_btnPreview addSubview:label];
        label.text = @"预览";
        label.textColor = TitleColor;
        label.textAlignment = NSTextAlignmentCenter;
        [_btnPreview addSubview:label];
    
    
        [_btnPreview addTarget:self action:@selector(didClickPreviewButton) forControlEvents:UIControlEventTouchUpInside];
    
        [self addSubview: _btnPreview];
        
        //右侧分割线
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(self.assistantPhone.rightEdge, 0, 1, ActualHeight(95))];
        view.backgroundColor = [UIColor whiteColor];
        [self addSubview:view];
        
    }
    return _btnPreview;

}
- (void)didClickPreviewButton{
    NSIndexPath *indexPatch = [((UITableView *)self.superview.superview) indexPathForCell:self];
    
    if ([self.delegate respondsToSelector:@selector(didClickTodayPreViewWithIndex:)]) {
        [self.delegate didClickTodayPreViewWithIndex:indexPatch];
    }
    
}
- (void)didClickGetCarButton{
    NSIndexPath *indexPatch = [((UITableView *)self.superview.superview) indexPathForCell:self];
    
    if ([self.delegate respondsToSelector:@selector(didClickTodaygetCarWithIndex:)]) {
        [self.delegate didClickTodaygetCarWithIndex:indexPatch];
    }
    
}

- (void)updateDataWithModel:(ICMAppointmentTodayModel *)model{
    self.contentView.backgroundColor = Color(0xF1F3F3);
    self.time.text = model.time?[ICrEAMTool getDateHourMinuteWithTimeInterval:model.time]:@"";
    /***************1小时内预约待进站**************/
    NSTimeInterval intervel=[[NSDate date] timeIntervalSince1970];
    NSInteger time=[model.time longLongValue]/1000-intervel;
    BOOL isOneHour=(3600-time)>0?YES:NO;
    if (time<0) {
        isOneHour=NO;
    }
    if (isOneHour && [model.status isEqualToString:ICMEnumIntToString(ICMEnumGetInStatusUnIn)]) {
        self.contentView.backgroundColor=[ICrEAMTool isVW]?RGBA(0, 154, 218, 0.15):RGBA(62, 155, 35, 0.15);
    }
    /******************/
    
    /**************超过15分钟延迟进站*************/
    BOOL isOver15Min = (intervel - [model.time longLongValue]/1000 - 15*60) > 0?YES:NO;
    if([model.status isEqualToString:ICMEnumIntToString(ICMEnumGetInStatusUnIn)])
    {
        //所有延迟进站
//        self.contentView.backgroundColor=[ICrEAMTool isVW]?RGBA(10, 134, 118, 0.15):RGBA(52, 125, 55, 0.15);
        //超过15分钟延迟进站
        if(isOver15Min)
        {
            self.status.textColor = [UIColor redColor];
            self.time.textColor = [UIColor redColor];
        }
        else
        {
            self.status.textColor = [UIColor blackColor];
            self.time.textColor = [UIColor blackColor];
        }
    }
    else
    {
        self.status.textColor = [UIColor blackColor];
        self.time.textColor = [UIColor blackColor];
    }
    /******************************************/
    self.status.text = model.status?[ICrEAMTool getCodeModelForCode:[NSString stringWithFormat:@"%@",model.status]].desc:@"";
    if([model.status isEqualToString:ICMEnumIntToString(ICMEnumGetInStatusDelayIn)] || [model.status isEqualToString:ICMEnumIntToString(ICMEnumGetInStatusAdvanceIn)] || [model.status isEqualToString:ICMEnumIntToString(ICMEnumGetInStatusOntimeIn)])
    {
        //对于已进站的 不管准时履约还是 延迟履约或提前履约均显示为已进站
        self.status.text = @"已进站";
    }
    
    self.plateNum.text = model.plateNum?:@"";
    
    //21141001 未进站
    //21141002 延迟履约
    //21141003 提前履约
    //21141004 准时履约
    //21141005 取消
    
    
    self.customerName.text = model.customerName?:@"";
    self.customerPhone.text = model.customerPhone?:@"";
    self.assistantName.text = model.assistantName?:@"";
    self.assistantPhone.text = model.assistantPhone?:@"";
    self.btnGetCar.hidden = NO;
    if (![[NSString stringWithFormat:@"%@",model.status] isEqualToString:ICMEnumIntToString(ICMEnumGetInStatusUnIn)] || [model.HAS_RECEPTION isEqualToString:@"1"]) {
        self.btnGetCar.hidden = YES;
    }
    self.btnPreview.hidden = NO;
    
}
@end
